package com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use;

import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.Handler;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.AddressRequest;
import com.ruyuan2020.im.design.ChainOfResponsibilityPattern.use.request.Request;

// 具体处理者角色C - 地址验证
class AddressHandler extends Handler {
    @Override
    public void handleRequest(Request request) {
        if (request instanceof AddressRequest) {
            AddressRequest addressRequest = (AddressRequest) request;
            if (addressRequest.getAddress() != null && addressRequest.getAddress().isValid()) {
                System.out.println("地址验证通过！");
            } else {
                System.out.println("地址验证失败！");
                return; // 验证失败，不再传递请求
            }
        }
        // 正常情况下，这里可以处理请求或结束处理，但为了示例简单性，不在这里做任何额外处理
    }
}